﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dukou.Domain;
using Dukou.Dao;
using Spring.Transaction.Interceptor;

namespace Dukou.BizService.Implement
{
    /// <summary>
    /// 实体业务服务类
    /// </summary>
    /// <typeparam name="D"></typeparam>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="TId"></typeparam>
    [Serializable]
    public class EntityBizService<D, T, TId> : IEntityBizService<D, T, TId>
        where D : INHibernateDao<T, TId>
        where T : IEntity<TId>
    {
        public D EntityDao { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T FindById(TId id)
        {
            return this.EntityDao.FindById(id);
        }

        public IList<T> SelectAll()
        {
            return this.EntityDao.SelectAll();
        }

        [Transaction(ReadOnly=false)]
        public TId Save(T entity)
        {
            return this.EntityDao.Save(entity);
        }

        [Transaction(ReadOnly = false)]
        public void SaveOrUpdate(T entity)
        {
            this.EntityDao.SaveOrUpdate(entity);
        }
        
        [Transaction(ReadOnly = false)]
        public void Update(T entity)
        {
            this.EntityDao.Update(entity);
        }

        [Transaction(ReadOnly = false)]
        public void Delete(T entity)
        {
            this.EntityDao.Delete(entity);
        }

        [Transaction(ReadOnly = false)]
        public void Delete(Type type, TId id)
        {
            this.EntityDao.Delete(type, id);
        }
    }
}
